package com.ruoyi.project.order.deposit.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.order.deposit.domain.Deposit;
import com.ruoyi.project.order.deposit.service.IDepositService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 押金记录Controller
 * 
 * @author yyj
 * @date 2021-05-13
 */
@Controller
@RequestMapping("/order/deposit")
public class DepositController extends BaseController
{
    private String prefix = "order/deposit";

    @Autowired
    private IDepositService depositService;

    @RequiresPermissions("order:deposit:view")
    @GetMapping()
    public String deposit()
    {
        return prefix + "/deposit";
    }

    /**
     * 查询押金记录列表
     */
    @RequiresPermissions("order:deposit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Deposit deposit)
    {
        startPage();
        List<Deposit> list = depositService.selectDepositList(deposit);
        return getDataTable(list);
    }

    /**
     * 导出押金记录列表
     */
    @RequiresPermissions("order:deposit:export")
    @Log(title = "押金记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Deposit deposit)
    {
        List<Deposit> list = depositService.selectDepositList(deposit);
        ExcelUtil<Deposit> util = new ExcelUtil<Deposit>(Deposit.class);
        return util.exportExcel(list, "deposit");
    }

    /**
     * 新增押金记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存押金记录
     */
    @RequiresPermissions("order:deposit:add")
    @Log(title = "押金记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Deposit deposit)
    {
        return toAjax(depositService.insertDeposit(deposit));
    }

    /**
     * 修改押金记录
     */
    @GetMapping("/edit/{depositId}")
    public String edit(@PathVariable("depositId") Long depositId, ModelMap mmap)
    {
        Deposit deposit = depositService.selectDepositById(depositId);
        mmap.put("deposit", deposit);
        return prefix + "/edit";
    }

    /**
     * 修改保存押金记录
     */
    @RequiresPermissions("order:deposit:edit")
    @Log(title = "押金记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Deposit deposit)
    {
        return toAjax(depositService.updateDeposit(deposit));
    }

    /**
     * 删除押金记录
     */
    @RequiresPermissions("order:deposit:remove")
    @Log(title = "押金记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(depositService.deleteDepositByIds(ids));
    }



    @GetMapping("/report")
    public String getReportView(){
        return "echarts";
    }

    @PostMapping("/report")
    @ResponseBody
    public AjaxResult getReport(){
        AjaxResult result=AjaxResult.success();
        List<Object[]> list=depositService.getMonthReport("");
        result.put("yb",list);
        list=depositService.getMonthReport("1");
        result.put("yb-1",list);
        list=depositService.getMonthReport("2");
        result.put("yb-2",list);
        list=depositService.getMonthReport("3");
        result.put("yb-3",list);
        list=depositService.getMonthReport("4");
        result.put("yb-4",list);
        return result;
    }
}
